package com.ymatou.iapi.dglogin.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.ymatou.common.lang.CipherUtil;
import com.ymatou.iapi.dglogin.parameter.WxbindBean;
import com.ymatou.iapi.dglogin.service.WxbindCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.parameter.UserDto;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.DataUtil.Random;
import com.ymttest.utils.TestDataManager;
/**
*微信绑定Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Wxbind{
	private static WxbindBean wxbindBean;
	private static WxbindCall wxbindCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("微信绑定Test");
	}

	@Before
	public void caseUp() {
		wxbindBean=new WxbindBean();
		wxbindCall=new WxbindCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(wxbindCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Wxbind_001() {
		Logger.start(true,"商家绑定微信，成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			
			JsonArray dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			System.out.println(dgUserBindInfo);
			
			String token =TestDataManager.getRandomUUID().toString();
			wxbindBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			wxbindBean.setUserId(user);
			wxbindBean.setCode("123123");
			wxbindBean.setAppSource(DGUserCallService.DG_SellerWxApp);
			 
			wxbindCall.addHeader("mock", "mock-enable");
			wxbindCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxbindCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			wxbindCall.addHeader("mockParam-1-token",token);
			wxbindCall.addHeader("mockParam-1-openId",u.getOpenId());
			
			wxbindCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxbindCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxbindCall.addHeader("mockParam-2-unionId",u.getUnionId());
			wxbindCall.addHeader("mockParam-2-openId",u.getOpenId());
			wxbindCall.addHeader("mockParam-2-nickname",u.getNickname());
			
			wxbindCall.setData(wxbindBean);
			wxbindCall.callService();
			Logger.verifyEquals("200", wxbindCall.getString("status"), "验证code");
			Logger.verifyEquals("true", wxbindCall.getString("success"), "验证code");
			
			JsonArray dgUserBindInfo1 = DGUserCallService.getDGUserBindInfo(user);
			System.out.println(dgUserBindInfo1);
			Logger.verifyEquals(2,dgUserBindInfo1.size(),"验证绑定成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Wxbind_002() {
		Logger.start(true,"已经绑定过，失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			
			JsonArray dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			System.out.println(dgUserBindInfo);
			
			String token =TestDataManager.getRandomUUID().toString();
			wxbindBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			wxbindBean.setUserId(user);
			wxbindBean.setCode("123123");
			wxbindBean.setAppSource(DGUserCallService.DG_SellerWxApp);
			
			wxbindCall.addHeader("mock", "mock-enable");
			wxbindCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxbindCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			wxbindCall.addHeader("mockParam-1-token",token);
			wxbindCall.addHeader("mockParam-1-openId",u.getOpenId());

			wxbindCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxbindCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxbindCall.addHeader("mockParam-2-unionId",u.getUnionId());
			wxbindCall.addHeader("mockParam-2-openId",u.getOpenId());
			wxbindCall.addHeader("mockParam-2-nickname",u.getNickname());
			
			wxbindCall.setData(wxbindBean);
			wxbindCall.callService();
			wxbindCall.callService();
			Logger.verifyEquals("200", wxbindCall.getString("status"), "验证code");
			Logger.verifyEquals("false", wxbindCall.getString("success"), "验证code");
			
			JsonArray dgUserBindInfo1 = DGUserCallService.getDGUserBindInfo(user);
			System.out.println(dgUserBindInfo1);
			Logger.verifyEquals(2,dgUserBindInfo1.size(),"验证绑定成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Wxbind_003() {
		Logger.start(true,"用户id输入错误，失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			
			JsonArray dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			System.out.println(dgUserBindInfo);
			
			String token =TestDataManager.getRandomUUID().toString();
			wxbindBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			wxbindBean.setUserId(123123123);
			wxbindBean.setCode("123123");
			wxbindBean.setAppSource(DGUserCallService.DG_SellerWxApp);
			
			wxbindCall.addHeader("mock", "mock-enable");
			wxbindCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxbindCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			wxbindCall.addHeader("mockParam-1-token",token);
			wxbindCall.addHeader("mockParam-1-openId",u.getOpenId());

			wxbindCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxbindCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxbindCall.addHeader("mockParam-2-unionId",u.getUnionId());
			wxbindCall.addHeader("mockParam-2-openId",u.getOpenId());
			wxbindCall.addHeader("mockParam-2-nickname",u.getNickname());
			
			wxbindCall.setData(wxbindBean);
			wxbindCall.callService();
			wxbindCall.callService();
			Logger.verifyEquals("200", wxbindCall.getString("status"), "验证code");
			Logger.verifyEquals("false", wxbindCall.getString("success"), "验证code");
			
			JsonArray dgUserBindInfo1 = DGUserCallService.getDGUserBindInfo(user);
			System.out.println(dgUserBindInfo1);
			Logger.verifyEquals(1,dgUserBindInfo1.size(),"验证绑定成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Wxbind_004() {
		Logger.start(true,"coke为空，失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			JsonArray dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			System.out.println(dgUserBindInfo);
			String token =TestDataManager.getRandomUUID().toString();
			wxbindBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			wxbindBean.setUserId(user);
			wxbindBean.setCode("123123");
			wxbindBean.setAppSource(DGUserCallService.DG_SellerWxApp);
			
			wxbindCall.setData(wxbindBean);
			wxbindCall.callService();
			wxbindCall.callService();
			Logger.verifyEquals("200", wxbindCall.getString("status"), "验证code");
			Logger.verifyEquals("false", wxbindCall.getString("success"), "验证code");
			
			JsonArray dgUserBindInfo1 = DGUserCallService.getDGUserBindInfo(user);
			System.out.println(dgUserBindInfo1);
			Logger.verifyEquals(1,dgUserBindInfo1.size(),"验证绑定成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Wxbind_005() {
		Logger.start(true,"绑定后，头像会变化，");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			
			JsonArray dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			System.out.println(dgUserBindInfo);
			
			String token =TestDataManager.getRandomUUID().toString();
			wxbindBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			wxbindBean.setUserId(user);
			wxbindBean.setCode("123123");
			wxbindBean.setAppSource(DGUserCallService.DG_SellerWxApp);
			
			wxbindCall.addHeader("mock", "mock-enable");
			wxbindCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxbindCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			wxbindCall.addHeader("mockParam-1-token",token);
			wxbindCall.addHeader("mockParam-1-openId",u.getOpenId());

			wxbindCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxbindCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxbindCall.addHeader("mockParam-2-unionId",u.getUnionId());
			wxbindCall.addHeader("mockParam-2-openId",u.getOpenId());
			wxbindCall.addHeader("mockParam-2-nickname",u.getNickname());
			
			wxbindCall.setData(wxbindBean);
			wxbindCall.callService();
			Logger.verifyEquals("200", wxbindCall.getString("status"), "验证code");
			Logger.verifyEquals("true", wxbindCall.getString("success"), "验证code");
			
			JsonArray dgUserBindInfo1 = DGUserCallService.getDGUserBindInfo(user);
			System.out.println(dgUserBindInfo1);
			Logger.verifyEquals(2,dgUserBindInfo1.size(),"验证绑定成功");
			
			
			UserDto u1 = DGUserCallService.getDGUserInfo(user);
			Logger.verifyNotEquals(u.getLogoUrl(), u1.getLogoUrl(), "头像变化");
//			Logger.verifyNotEquals(u.getNickname(), u1.getNickname(), "昵称变化");
//			Logger.verifyNotEquals(u.getUserGender(), u1.getGender(), "性别变化");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}